#include <iostream>
#include <string>
#include "Protocol.hpp"
// 假设你已经定义了 Encode, Decode, Request 和 Response 类

int main()
{
    //--- 测试 Encode 和 Decode ---

    //创建要编码的数据并输出
    std::string original_content = "Hello, world!";
    std::cout<<"明文"<<original_content<<std::endl;

    // 对数据进行编码 并输出
    std::string encoded_package = Encode(original_content);
    std::cout << "Encoded package: " << encoded_package << std::endl;

    // 创建一个用来存储解码结果的变量
    std::string decoded_content;

    // 对编码的数据包进行解码
    bool success = Decode(encoded_package, &decoded_content);

    // 检查解码是否成功
    if (success) {
        std::cout << "Decoded content: " << decoded_content << std::endl;
        if (decoded_content == original_content) {
            std::cout << "Encode/Decode test passed!" << std::endl;
        } else {
            std::cout << "Encode/Decode test failed!" << std::endl;
        }
    } else {
        std::cout << "Decode failed!" << std::endl;
    }

    //--- 测试 Request 类 ---

    //创建一个 Request 对象，参数为 x = 3, y = 4, op = '+'
    Request req(3, 4, '+');
    std::string serialized_request;
    req.Serialize(&serialized_request); // 序列化请求

    std::cout << "Serialized request: " << serialized_request << std::endl;

    // 反序列化请求
    Request req2;
    if (req2.Deserialize(serialized_request))
    {
        req2.DebugPrint(); // 输出请求的内容
    }
    else
    {
        std::cout << "Request deserialization failed!" << std::endl;
    }

    // --- 测试 Response 类 ---

    // 创建一个 Response 对象，结果为 7，错误码为 0
    Response res(7, 0);
    std::string serialized_response;
    res.Serialize(&serialized_response); // 序列化响应

    std::cout << "Serialized response: " << serialized_response << std::endl;

    // 反序列化响应
    Response res2;
    if (res2.Deserialize(serialized_response))
    {
        res2.DebugPrint(); // 输出响应的内容
    }
    else
    {
        std::cout << "Response deserialization failed!" << std::endl;
    }

    return 0;
}
